<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen,fancybox'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <input type="hidden" readonly id="productMember" name="productMember"  class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">柜号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="refusedPlanNo" name="refusedPlanNo" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <form>
                <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                    <button class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                        <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                    </button>
                </div>
            </form>
            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/billRefused/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="refusedRemark" name="refusedRemark" value="" class="form-control">
                </div>
                <div id="id" hidden="hidden" name="id"></div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>



<div id="layer_claim_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <div id="claimId" hidden="text" name="claimId"></div>
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-claim-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">索赔附件</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <button  class="layui-btn layui-btn-sm import-claim-btn" style="margin-left: -2px" type="button" id="import-claim-btn"  name="import-claim-btn">
                        <i class="layui-icon"></i>导入索赔附件
                    </button>
                    <input type="hidden" id="billClaimFile" name="billClaimFile">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">POD附件</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <button  class="layui-btn layui-btn-sm import-pod-btn" style="margin-left: -2px" type="button" id="import-pod-btn"  name="import-pod-btn">
                        <i class="layui-icon"></i>导入合同附件
                    </button>
                    <input type="hidden" id="billPodFile" name="billPodFile">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-claim-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload,imgbox,layui,upload'}){}%>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        var index=null;
        upload.render({
            elem: '#import-claim-btn', //绑定元素,
            accept:'file',
            url: '/sea/physical/refusedTax/import/', //上传接口
            data:{},
            before:function () {
                index=layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $("#billClaimFile").val(data.data);
                        layer.close(index);
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.close(index);
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        var index=null;
        upload.render({
            elem: '#import-pod-btn', //绑定元素,
            accept:'file',
            url: '/sea/physical/refusedTax/import/', //上传接口
            data:{},
            before:function () {
                index=layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $("#billPodFile").val(data.data);
                        layer.close(index);
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.close(index);
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });


    var $relatedTable = $('#relatedTable');
    $(function(){
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
        //START 表格配置
        $relatedTable.bootstrapTable({
            detailView: true,
            columns: [
                {
                    title: '海关单编号',
                    field: 'refusedNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'refusedPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'refusedChannel',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '收货金额',
                    field: 'refusedCreateMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票金额',
                    field: 'refusedBillMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '财务审批金额',
                    field: 'refusedFinanceMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '索赔发票',
                    field: 'billClaimFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: 'POD发票',
                    field: 'billPodFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '关联PO号',
                    field: 'produceNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '备注',
                    field: 'refusedRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $(".pay-btn").on('click', function () {
                    //详情
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%', '100%'],
                        content: ['/sea/supply/bill/addPage.do?id='+id, 'yes']
                    });
                });
                $(".claim-btn").on('click', function () {
                    //详情
                    var id = $(this).attr('data-val');
                    $('#claimId').val(id);
                    layer.open({
                        type:1,
                        title:'添加发票',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_claim_window')
                    })
                });
                $(".remark-btn").on('click', function () {
                    //详情
                    var id = $(this).attr('data-val');
                    $('#id').val(id);
                    layer.open({
                        type:1,
                        title:'添加备注',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });

                $('.detail-btn').on('click',function(){
                    var refusedPlanNo = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/supply/billRefused/record.do?refusedPlanNo='+refusedPlanNo, 'yes']
                    });
                });


            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });


        function InitSubTable (index, row, $detail) {
            var parentId = row.id;
            cur_table = $detail.html('<table id="child_table" class="table table-striped table-hover"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/supply/bill/findByRefusedId',
                method: 'get',
                clickToSelect: true,
                queryParams: { refusedId: parentId },
                ajaxOptions: { refusedId: parentId },
                //height: 500,
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        title: '供应商',
                        field: 'supplierName',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '柜号',
                        field: 'createPlanNo',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '不含税金额',
                        field: 'billPrice',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '税额',
                        field: 'billTax',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '含税金额',
                        field: 'billMoney',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '发票号码',
                        field: 'billNumber',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '发票代码',
                        field: 'billCode',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '发票图片',
                        field: 'billImg',
                        align: 'center',
                        valign: 'middle',
                        formatter:function (v,r) {
                            if(null!=v && v!=''){
                                return '<a class="fancybox" href="'+v+'"><img src="' + v + '" style="width:80px;height:60px;"/></a>';;
                            }else{
                                return '';
                            }
                        }
                    },
                    {
                        title: '状态',
                        field: 'billStatus',
                        align: 'center',
                        valign: 'middle',
                        formatter:function (v,r) {
                            var result='';
                            switch (v) {
                                case 0:
                                    result='待审核';
                                    break;
                                case 1:
                                    result='审核中';
                                    break;
                                case 3:
                                    result='已拒绝:'+r.billRemark;
                                    break;
                                case 2:
                                    result='审核通过';
                                    break;

                                default:
                                    result='';
                            }
                            return result;
                        }
                    },
                    {
                        field: 'operate',
                        title: '操作',
                        align: 'center',
                        valign: 'middle',
                        formatter: optFormatter2
                    }
                ],
                onLoadSuccess : function(){
                    //修改按钮
                    $('.edit-btn').on('click',function(){
                        var id = $(this).attr('data-val');
                        layer.open({
                            title: false,
                            closeBtn: 0,
                            type: 2,
                            area: ['100%','100%'],
                            skin: 'layer-ext-espresso',
                            content: ['/sea/supply/bill/editPage.do?id='+id, 'yes']
                        });
                    });
                    $('.del-btn').on('click',function(){
                        var id = $(this).attr('data-val');
                        layer.confirm('确定要删除当前？', {
                            btn: ['确定','取消'],title:'提示'
                        }, function(){
                            $.post('/sea/supply/bill/delete.do',{id: id},function(data){
                                if( data.ok ){
                                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                        //刷新页面
                                        $relatedTable.bootstrapTable('refresh');
                                    });
                                }else{
                                    layer.msg(data.msg,{icon: 0,time: 1500});
                                }
                            });
                        });
                    });
                    $('.btn-send').on('click',function(){
                        var id = $(this).attr('data-val')
                        layer.confirm('确定要推送当前数据？', {
                            btn: ['确定','取消'],title:'提示'
                        }, function(){
                            layer.closeAll();
                            layer.load();
                            $.post('/sea/supply/bill/usave.do',{id: id,billStatus:1,flag:1},function(data){
                                if( data.ok ){
                                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                        //刷新页面
                                        cur_table.bootstrapTable('refresh');
                                        layer.closeAll();
                                    });
                                }else{
                                    layer.closeAll(); //关闭弹窗
                                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                                            layer.closeAll();
                                        }});
                                }
                            });
                        });
                    });
                }
            });
        }


        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/billRefused/findByCnd?'+$('#search-form').serialize() });
        });

        //操作菜单
        function optFormatter(value,row){
            var content= '';
            content += '<button class="remark-btn btn btn-xs btn-success" data-val="' + row.id + '" title="添加备注"><i class="fa fa-check-square-o" aria-hidden="true"></i> 添加备注 </button>&nbsp;';
            content += '<button class="claim-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="添加备注"><i class="fa fa-check-square-o" aria-hidden="true"></i> 物流索赔发票 </button>&nbsp;';
            content += '<button class="pay-btn btn btn-xs btn-success" data-val="' + row.id + '" title="添加发票信息"><i class="fa fa-check-square-o" aria-hidden="true"></i> 添加发票信息 </button>';
            content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.refusedPlanNo+'" title="查看记录"> 查看记录</button>';
            return content;
        }

        function optFormatter2(value,row){
            var content= '';
            if(row.billStatus==0) {
                content += '<button class="btn-send btn btn-xs btn-success" data-val="' + row.id + '" title="推送">  推送至财务</button>';
                content += '&nbsp;<button class="edit-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i>  </button>';
                content += '<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i>  </button>';
            }
            return content;
        }
    });

    //提交表单
    $('.save-btn').on('click',function(){
        var id=$("#id").val();
        //清关计划
        layer.confirm('确定要修改当前计划？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/billRefused/usave.do',{id:id,refusedRemark:$("#refusedRemark").val()},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    $('.save-claim-btn').on('click',function(){

        var id=$("#claimId").val();
        //清关计划
        layer.confirm('确定要修改当前计划？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/billRefused/usave.do',{id:$("#claimId").val(),billClaimFile:$("#billClaimFile").val(),billPodFile:$("#billPodFile").val()},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/supply/billRefused/export?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
